//
//  StartMovieViewController.m
//  开源中国
//
//  Created by hcios on 16/12/7.
//  Copyright © 2016年 鹿林. All rights reserved.
//

#import "StartMovieViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AVKit/AVKit.h>
#import "XYJLoginViewController.h"

@interface StartMovieViewController ()

@property (nonatomic, strong) MPMoviePlayerController * player;

@end

@implementation StartMovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setUpVideoPlayer];
    // Do any additional setup after loading the view.
}


- (void)setUpVideoPlayer{

    
    self.player = [[MPMoviePlayerController alloc] initWithContentURL:_movieURL];
    [self.view addSubview:self.player.view];
    self.player.shouldAutoplay = YES;
    [self.player setControlStyle:MPMovieControlStyleNone];
    self.player.repeatMode = MPMovieRepeatModeOne;
    [self.player.view setFrame:self.view.bounds];
    self.player.view.alpha = 0;
    [UIView animateWithDuration:3 animations:^{
        self.player.view.alpha = 1;
        [self.player prepareToPlay];
    }];
    
    [self setUpLoginView];
}


-(void) setUpLoginView{

    UIButton * enterMainButton = [[UIButton alloc] init];
    enterMainButton.frame = RECT_MAKE(24, SCREEN_HEIGHT - 80, SCREEN_WIDTH - 48, 48);
    enterMainButton.backgroundColor = [UIColor redColor];
    enterMainButton.layer.borderWidth = 1;
    enterMainButton.layer.cornerRadius = 24;
    enterMainButton.layer.borderColor = [UIColor whiteColor].CGColor;
    [enterMainButton setTitle:@"进入应用" forState:UIControlStateNormal];
    enterMainButton.alpha = 0;
    [self.player.view addSubview:enterMainButton];
    [self.view addSubview:enterMainButton];
    [enterMainButton addTarget:self action:@selector(enterMainAction:) forControlEvents:UIControlEventTouchUpInside];
    [UIView animateWithDuration:3.0 animations:^{
        enterMainButton.alpha = 1.0;
    }];
}

- (void)enterMainAction:(UIButton *)btn {

    XYJLoginViewController * VC = [[XYJLoginViewController alloc] init];
    [self presentViewController:VC animated:YES completion:nil];
}

@end
